/**
 * Chrowety
 * options/init.js
 * @require 
 * 		- background.html
*/

var
bg 		= chrome.extension.getBackgroundPage,
cfg 	= bg().cfg,
twitter = bg().twitter,
utils 	= bg().utils,
OAuth	= bg().OAuth,
guia 	= cfg.isLogged() ? ( cfg.uiPref('optionsTab') || 'general') : 'accounts';

var DEBUG = false;

$(document).ready(function(){   
    i18n.init();
    menu.init(guia);
    dataCfg.init();
    accounts.init();
    gestures.init();    
    
    if(DEBUG)
    {    	
    	bdd.initAll('i18n', 'utils.chrome', 'utils.rgx', 'accounts', 'dataCfg', 'gestures', 'menu', 'checkbox', 'lightBox', 'db', 'migration');
    }
});

function $S(q)
{
	return document.querySelectorAll(q);
};


function reInit()
{
    menu.init(guia);
    dataCfg.init();
    accounts.init();
}

chrome.extension.onRequest.addListener(function( request, sender, sendResponse ){
	sendResponse({});
	switch( request.action )
	{
		case 'migrate':
			//console.log('request to migrate');
			accounts.migrate();
			break;
		case 'restart':
			window.location.reload();
			break;
		case 'autorizar':
			accounts.accessToken(request, sender);
			break;
	}
});